﻿////页面加载
$(document).ready(function () {
    $("#btnSave").bind("click", btnSave_click);
    //$("#btnCancel").bind("click", btnCancel_click);
    Count_Total();
})

// jquery mobile 初始化完毕后的事件
$(document).on("pageinit", "#mainPage", function () {

    Count_Total();

});

function btnSave_click() {
    //表单验证
    //if (!ValidateFrom()) {
    //    return false;
    //}

    var v_CardID = $("#Code").val();
    if (v_CardID == "")
    {
        alert("会员卡必填！");
        return ;
    }

    if (confirm("你确使提交订单？"))
    {
        //异步提交表单,表单中input元素必须设置name 属性
        $.post("/WeiXin/SaveOrder?action=Update", $("#fmSave").serialize(), function (result) {
            if (result.data >0) {
                //订单购买成功,转到成功页面 
                window.location.href = "/WeiXin/CheckBill?OrderID="+result.data;
            }
            else {
                alert("订购失败，请稍后重试");
            }
        },"Json");
    }

}

function Count_Total()
{
    var totalList = $("#olOrder li span[id='total']");
    var v_orderTotal = 0;
    $.each(totalList, function (i, item) {
        v_orderTotal +=parseFloat($(item).html());
    });
    $("#OrderTotal").html(v_orderTotal);
}

function Quantity_onchange(e)
{
    var quantity = $(e).val();
    var price= $(e).parent().parent().find("#pPrice").html();
    $(e).parent().parent().find("#total").html(price * quantity);

    //刷新总价
    Count_Total();
}

function btnDel_click(e)
{
    
}

function ValidateFrom() {
    return true;
}

function btnCancel_click() {
    window.history.go(-1);
}
